(function() {
    base2Cells.util.namespace("base2Cells.ytPlaylist");

    /**
     * @param cfg The configuration object.
     * <pre>
     *  {
     *      id: The passed in youtube id.
     *      idNum: The id number of this video.
     *      ownerCt: The owner container.
     *  }
     * </pre>
     */
    base2Cells.ytPlaylist.Video = function(cfg) {
        /** The video id. */
        this.ytId = "";
        /** The html used to embed the youtube video. */
        this.embedHtml = "";
        /** DOM element that holds this video. */
        this.el = null;
        /** This item container. */
        this.ownerCt = null;
        /** Boolean describing if this video is showing. */
        this.showing = false;

        // The inner html string to use for embedding the video.
        var embedString = '<object width="400" height="300">'
            + '<param name="movie" value="http://www.youtube.com/v/[replaceMe]&autoplay=1&hl=en_US&fs=1&"></param>'
            + '<param name="allowFullScreen" value="true"></param>'
            + '<param name="allowscriptaccess" value="always"></param>'
            + '<embed style="z-index: 200" wmode="opaque" src="http://www.youtube.com/v/[replaceMe]&autoplay=1&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="400" height="300"></embed>'
            + '</object>';

        // Constructor
        (function(cfg) {
            this.ytId = cfg.id;
            this.idNum = cfg.idNum;
            this.ownerCt = cfg.ownerCt;

            // Generate the embed html required to run the video.
            this.embedHtml = embedString.replace(/\[replaceMe\]/g, this.ytId);

            //Create the dom element.
            this.el = document.createElement('div');
            this.el.setAttribute('class', 'video');
            this.el.setAttribute('id', 'video-' + this.idNum);
            this.el.innerHTML = this.embedHtml;
        }).apply(this, [cfg]);

        /** @return The video element. */
        this.getEl = function() {
            return this.el;
        }

        /**
         * Remove this video from the container.
         */
        this.remove = function() {
            this.ownerCt.removeChild(this.el);
            this.showing = false;
        }

        /**
         * Add this video to the owner container.
         */
        this.apply = function() {
            this.ownerCt.appendChild(this.el);
            this.showing = true;
        }
    }
})();
